"""
文件名: CartInterface.py
作用: 封装购物车相关接口
作者: 健哥
"""

from Untils.SendMethod import SendMethod
from Interface.MemberInterface import MemberInterface


class CartInterface:
    def __init__(self):
        self.url = 'http://139.159.146.104:8083'
        member = MemberInterface()
        self.headers = member.get_token(username='冰红茶', password='123456')

    def add_cart(self, payload):
        """
        添加购物车接口
        :param payload: 请求参数
        :return:
        """
        url = self.url + '/cart/add'
        return SendMethod.send_method(method='post', url=url, json=payload, headers=self.headers)

    def get_cart_list(self):
        """
        获取某个会员的购物车列表
        :return:
        """
        url = self.url + '/cart/list'
        return SendMethod.send_method(method='get', url=url, headers=self.headers)


if __name__ == '__main__':
    cart = CartInterface()
    payload = {
        "createDate": "2022-06-01T06:35:19.691Z",
        "deleteStatus": 0,
        "id": 0,
        "modifyDate": "2022-06-01T06:35:19.691Z",
        "price": 649,
        "productAttr": '[{"key":"颜色","value":"金色"},{"key":"容量","value":"16G"}]',
        "productBrand": "小米",
        "productCategoryId": 0,
        "productId": 28,
        "productName": "小米 红米5A 全网通版 3GB+32GB 香槟金 移动联通电信4G手机 双卡双待",
        "productPic": "shenzhen.aliyuncs.com/mall/images/20180615/5a9d248cN071f4959.jpg",
        "productSkuCode": "201808270027002",
        "productSkuId": 102,
        "productSn": "7437789",
        "productSubTitle": "8天超长待机，137g轻巧机身，高通骁龙处理器小米6X低至1299，点击抢购",
        "quantity": 1
    }
    # print(cart.add_cart(payload=payload))
    print(cart.get_cart_list())
